package game.buff;

import game.worlds.IDisplay;
import hx.display.DisplayObject;
import hx.geom.Point;
import game.worlds.GameEffect;
import game.worlds.GameRole;
import game.buff.AttackScaleBuff;
import game.buff.AttackDefenseScaleBuff;
import game.buff.SpeedScaleBuff;

class Buff {
	/**
	 * BUFF的唯一ID
	 */
	public var id:String;

	/**
	 * BUFF生效的角色
	 */
	public var role:GameRole;

	/**
	 * BUFF的持续时间
	 */
	public var liveTime:Float = 0;

	/**
	 * BUFF是否可以强制覆盖
	 */
	public var canOverride:Bool = false;

	/**
	 * 渲染特效对象
	 */
	public var renderDisplay:IDisplay = null;

	/**
	 * 每帧都会调用一次
	 * @param target 
	 */
	dynamic public function onApplyBuffEffect(target:GameRole, dt:Float):Void {}

	/**
	 * 当BUFF被移除时触发
	 * @param target 
	 */
	dynamic public function onCleanBuffEffect(target:GameRole):Void {}

	/**
	 * 当BUFF被添加时触发
	 * @param target 
	 */
	dynamic public function onInitBuffEffect(target:GameRole):Void {}

	public function new(id:String, liveTime:Float) {
		this.id = id;
		this.liveTime = liveTime;
	}

	public function onUpdate(dt:Float):Void {
		liveTime -= dt;
		if (renderDisplay != null) {
			this.role.world.addDisplay(renderDisplay);
		}
		this.onApplyBuffEffect(this.role, dt);
	}

	/**
	 * buff初始化时
	 */
	public function onInit():Void {
		onInitBuffEffect(this.role);
	}

	/**
	 * buff清理时
	 */
	public function onClean():Void {
		onCleanBuffEffect(this.role);
		if (renderDisplay != null) {
			renderDisplay.clean();
			renderDisplay = null;
		}
	}
}
